package com.dongge.interceptor;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import java.util.Map;

/**
 * Created by Administrator on 2015/9/12.
 */
public class LoginInterceptor extends AbstractInterceptor{
    public LoginInterceptor() {
        super();
    }

    @Override
    public void init() {
        super.init();
    }

    @Override
    public void destroy() {
        super.destroy();
    }

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        ActionContext actionContext = invocation.getInvocationContext();
        Map<String,Object> session = actionContext.getSession();
        String user = (String)session.get("user");
        if(user !=null && user.equals("admin"))
            return invocation.invoke();
        return Action.LOGIN;
    }
}
